package com.egg.ylt.presenter.impl;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.util.Log;

import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.route.RouteSearch;
import com.egg.ylt.view.IShopPositionMapView;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.egg.ylt.presenter.IShopPositionMapViewPresenter;

import java.io.File;

/**
 * Created By Dlx
 * on 2018/12/11
 */
public class ShopPositionMapViewPresenterImpl extends BasePresenter<IShopPositionMapView> implements IShopPositionMapViewPresenter {
    private RouteSearch mRouteSearch;
    @Override
    public void getPosition(double lat , double lng) {
        LatLonPoint start = new LatLonPoint(lat,lng);
        RouteSearch.FromAndTo fromAndTo =new RouteSearch.FromAndTo(start,start);
        RouteSearch.WalkRouteQuery query = new RouteSearch.WalkRouteQuery(fromAndTo, 0);
        mRouteSearch.calculateWalkRouteAsyn(query);// 异步路径规划步行模式查询
    }

    @Override
    public void invokeAmap(double lat, double lng) {
        Intent intent = new Intent("android.intent.action.VIEW",
                android.net.Uri.parse("androidamap://navi?sourceApplication=婴联通&lat="+lat+"&lon="+lng+ "&dev=0&style=2"));
        intent.setPackage("com.autonavi.minimap");

//        intent.setData(Uri.parse("androidamap://poi?sourceApplication=softname&keywords="+需要导航的地址));

        if(isInstallByread("com.autonavi.minimap")){
            mView.invokeAmapApp(intent);
            Log.e("GasStation", "高德地图客户端已经安装") ;
        }else{
            CommonUtils.makeEventToast(mContext, "没有安装高德地图客户端", false);
        }
    }

    /**
     * 判断是否安装目标应用
     * @param packageName 目标应用安装后的包名
     * @return 是否已安装目标应用
     */
    private boolean isInstallByread(String packageName) {
        return new File("/data/data/" + packageName).exists();
    }

}
